dnl# -*- sh -*-
dnl# Process this file with autoconf to produce a configure script.
dnl#
dnl#Copyright (c) 1998 Juergen Sawinski <Juergen.Sawinski@urz.uni-heidelberg.de>
dnl#Copyright (c) 1997 1998 Guylhem AZNAR <guylhem@oeil.qc.ca>

AC_INIT(Makefile.in)
AC_CONFIG_AUX_DIR(autoconf)
AC_CONFIG_HEADER(config.h:autoconf/config.h.in)

version="asmix-1.5"

dnl# Setup command-line options

dnl# we need the standard prefixes defined early
test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix="$prefix"
eval "bindir=$bindir"
eval "datadir=$datadir"
eval "mandir=$mandir"

dnl# directories
AC_ARG_WITH(gnustep_dir,	[  --with-gnustep-dir=DIR  GNUstep directory [~/GNUstep] ],with_gnustep_dir=$withval, with_gnustep_dir="~/GNUstep")
AC_ARG_WITH(gnustep_lib,	[  --with-gnustep-lib=DIR  GNUstep/Library directory [~/GNUstep/Library] ],with_gnustep_lib=$withval, with_gnustep_lib="~/GNUstep/Library")
AC_ARG_WITH(afterdir,		[  --with-afterdir=DIR     user AfterStep dir [~/GNUstep/Library/AfterStep] ],with_afterdir=$withval, with_afterdir="~/GNUstep/Library/AfterStep")
AC_ARG_ENABLE(shaping, 		[  --enable-shaping        support shaped
windows [yes] ],enable_shaping=$enableval,enable_shaping="yes")
AC_ARG_ENABLE(jpeg,  		[  --enable-jpeg           support JPEG
image format [yes] ],enable_jpeg=$enableval,enable_jpeg="yes")

dnl# Check for compiler tools

AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PATH_PROG(RM, rm, rm)
AC_PATH_PROG(MV, mv, mv)
AC_PATH_PROG(CP, cp, cp)
AC_PATH_PROG(MKDIR, mkdir, mkdir)
AC_PATH_PROG(STRIP, strip, strip)

dnl# Remove -g

if test -n '`echo "$CFLAGS " | grep "\-g " 2> /dev/null`' ; then
  CFLAGS=`echo "$CFLAGS " | sed "s/-g //"`
fi

dnl# Add -Wall

if test "x$GCC" = "xyes"; then
  if test -z '`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`' ; then
    CFLAGS="$CFLAGS -Wall"
  fi
fi

dnl# Check for headers

AC_PATH_XTRA
AC_CHECK_HEADERS(sys/wait.h sys/time.h)
AC_CHECK_HEADERS(sys/statvfs.h sys/vfs.h sys/mount.h ustat.h)
AC_CHECK_HEADERS(machine/soundcard.h linux/soundcard.h linux/radio.h)
AC_CONFIG_HEADER(config.h)

dnl# Check for X

saved_cflags="$CFLAGS"
saved_ldflags="$LDFLAGS"

CFLAGS="$CFLAGS $X_CFLAGS"
LDFLAGS="$LDFLAGS $X_LDFLAGS $X_LIBS"

x_libs="$X_EXTRA_LIBS $X_PRE_LIBS"
AC_CHECK_LIB(X11, XOpenDisplay, [x_libs="-lX11 $x_libs"],,$x_libs)

dnl# Check for XPM library

VT_FIND_LIBXPM
HAVEXPM="NOXPM"
if test "x$have_xpm" = "xyes"; then
  HAVEXPM="XPM"
  x_libs="$x_libs $XPM_LIBS"
fi
for x in $X_CFLAGS; do
  XPM_CFLAGS=`echo " $XPM_CFLAGS " | sed "s@ $x @ @"`
done

dnl# Check for X shaped window extension

HAVESHAPE="NOSHAPE"
if test "x$enable_shaping" = "xyes"; then
  AC_CHECK_LIB(Xext, XShapeCombineMask, [x_libs="$x_libs -lXext" HAVESHAPE="SHAPE"],,$x_libs)
fi

CFLAGS="$saved_cflags"
LDFLAGS="$saved_ldflags"

dnl# Check for libjpeg

HAVEJPEG="NOJPEG"
if test "x$enable_jpeg" = "xyes"; then
  AC_CHECK_LIB(jpeg, jpeg_destroy_compress, [JPEG_LIB="-ljpeg" HAVEJPEG="JPEG"],,)
fi

dnl# Variable strings declaration

AC_SUBST(version)
AC_SUBST(with_locale)
AC_SUBST(HAVEXPM)
AC_SUBST(HAVESHAPE)
AC_SUBST(HAVEJPEG)
AC_SUBST(XPM_LIBS)
AC_SUBST(x_libs)
AC_SUBST(x_includes)
AC_SUBST(XEXT_LIB)
AC_SUBST(JPEG_LIB)
AC_SUBST(with_gnustep_dir)
AC_SUBST(with_gnustep_lib)
AC_SUBST(with_afterdir)

dnl# Write results

AC_CONFIG_HEADER(config.h)

dnl# Common parts of the Makefile
MAKEFILEDEFINES=./autoconf/Makefile.defines
MAKEFILECOMMON=./autoconf/Makefile.common
MAKEFILECOMMONLIB=./autoconf/Makefile.common.lib

AC_SUBST_FILE(MAKEFILEDEFINES)
AC_SUBST_FILE(MAKEFILECOMMON)
AC_SUBST_FILE(MAKEFILECOMMONLIB)

AC_OUTPUT(\
autoconf/Makefile.defines \
autoconf/Makefile.common \
autoconf/Makefile.common.lib \
Makefile
)

echo "


AfterStep applet $version is now hopefully configured, just run : 
make ; make install
"
